{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.8-final"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python37864bit9859aadc2f9b4163a401bc1d107b5e60",
   "display_name": "Python 3.7.8 64-bit"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "[1, 4, 9, 16, 25]"
     },
     "metadata": {},
     "execution_count": 1
    }
   ],
   "source": [
    "'''\n",
    "Python 中可以通过组合一些值得到多种 复合 数据类型。其中最常用的 列表 ，可以通过方括号括起、逗号分隔的一组值（元素）得到。一个 列表 可以包含不同类型的元素，但通常使用时各个元素类型相同:\n",
    "'''\n",
    "squares = [1, 4, 9 ,16, 25]\n",
    "squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "(1, 25, [9, 16, 25])"
     },
     "metadata": {},
     "execution_count": 2
    }
   ],
   "source": [
    "'索引、切片'\n",
    "squares[0], squares[-1], squares[-3:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "[1, 4, 9, 16, 25]"
     },
     "metadata": {},
     "execution_count": 3
    }
   ],
   "source": [
    "'''\n",
    "所有的切片操作都返回一个包含所请求元素的新列表。 这意味着以下切片操作会返回列表的一个 浅拷贝:\n",
    "'''\n",
    "\n",
    "squares[:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]"
     },
     "metadata": {},
     "execution_count": 4
    }
   ],
   "source": [
    "'''\n",
    "列表同样支持拼接操作:\n",
    "'''\n",
    "squares + [36, 49, 64, 81, 100]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "[1, 8, 27, 64, 125]"
     },
     "metadata": {},
     "execution_count": 5
    }
   ],
   "source": [
    "'''\n",
    "与 immutable 的字符串不同, 列表是一个 mutable 类型，就是说，它自己的内容可以改变:\n",
    "'''\n",
    "cubs = [1, 8 ,27, 65, 125]\n",
    "cubs[3] = 64\n",
    "cubs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "[1, 8, 27, 64, 125, 216, 216, 216, 343]"
     },
     "metadata": {},
     "execution_count": 8
    }
   ],
   "source": [
    "'''\n",
    "你也可以在列表末尾通过 append() 方法 来添加新元素（我们将在后面介绍有关方法的详情）:\n",
    "'''\n",
    "\n",
    "cubs.append(216)\n",
    "cubs.append(7 ** 3)\n",
    "cubs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "['a', 'b', 'c', 'd', 'e', 'f', 'g']"
     },
     "metadata": {},
     "execution_count": 9
    }
   ],
   "source": [
    "'''\n",
    "给切片赋值也是可以的，这样甚至可以改变列表大小，或者把列表整个清空:\n",
    "'''\n",
    "\n",
    "letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g']\n",
    "letters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "['a', 'b', 'C', 'D', 'E', 'f', 'g']"
     },
     "metadata": {},
     "execution_count": 10
    }
   ],
   "source": [
    "letters[2:5] = ['C', 'D', 'E']\n",
    "letters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "['a', 'b', 'f', 'g']"
     },
     "metadata": {},
     "execution_count": 11
    }
   ],
   "source": [
    "letters[2:5] = []\n",
    "letters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "4"
     },
     "metadata": {},
     "execution_count": 12
    }
   ],
   "source": [
    "letters = ['a', 'b', 'c', 'd']\n",
    "len(letters)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "([['a', 'b', 'c'], [1, 2, 3]], ['a', 'b', 'c'], 'b')"
     },
     "metadata": {},
     "execution_count": 14
    }
   ],
   "source": [
    "a = ['a','b','c']\n",
    "b = [1, 2, 3]\n",
    "x = [a, b]\n",
    "x, x[0], x[0][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}